﻿package mortal.game.view.guild.cellrender
{
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.display.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.guild.otherpanel.*;
    import mortal.game.view.systemSetting.*;
    import mortal.mvc.core.*;

    public class GuildListCellRenderer extends GuildCellRenderer
    {
        private var _isMyGuildEffect:ScaleBitmap;
        private var _txtRank:GTextFiled;
        private var _bmpRank:GBitmap;
        private var _txtGuildName:GTextFiled;
        private var _txtGuildMaster:GTextFiled;
        private var _txtGuildPower:GTextFiled;
        private var _txtGuildLevel:GTextFiled;
        private var _txtGuildMembersNum:GTextFiled;
        private var _btnApplyGuild:GButton;
        private var _btnEnterManor:GButton;
        private var _btnFindingTalent:GButton;
        private var _fruits:GBitmap;
        private var _saveData:SMiniGuildInfo;

        public function GuildListCellRenderer()
        {
            var _loc_1:* = new Bitmap(new BitmapData(1, 1, true, 0));
            this.setStyle("downSkin", _loc_1);
            this.setStyle("overSkin", _loc_1);
            this.setStyle("upSkin", _loc_1);
            this.setStyle("selectedDownSkin", _loc_1);
            this.setStyle("selectedOverSkin", _loc_1);
            this.setStyle("selectedUpSkin", _loc_1);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            var _loc_1:* = GlobalStyle.textFormatPutong;
            _loc_1.align = "center";
            this._txtRank = UIFactory.gTextField("1", 16, 3, 20, 20, this);
            this._bmpRank = UIFactory.gBitmap("", 12, 0, this);
            this._txtGuildName = UIFactory.gTextField("1", 54, 3, 90, 20, this, _loc_1);
            this._txtGuildMaster = UIFactory.gTextField("xx", 153, 3, 90, 20, this, _loc_1);
            this._txtGuildPower = UIFactory.gTextField("0", 230, 3, 100, 20, this, GlobalStyle.textFormatPutong.right());
            this._txtGuildLevel = UIFactory.gTextField("1", 375, 3, 30, 20, this, GlobalStyle.textFormatPutong.right());
            this._txtGuildMembersNum = UIFactory.gTextField("1/1", 470, 3, 60, 20, this, _loc_1);
            this._btnApplyGuild = UIFactory.gButton("" + Language.getString(71093), 557, 1, 62, 22, this);
            this._btnApplyGuild.configEventListener(MouseEvent.CLICK, this.onMouseClick);
            this._btnEnterManor = UIFactory.gButton("" + Language.getString(71094), 557, 1, 62, 22, this);
            this._btnEnterManor.configEventListener(MouseEvent.CLICK, this.onMouseClick);
            this._btnFindingTalent = UIFactory.gButton("" + Language.getString(71095), 557, 1, 62, 22, this);
            this._btnFindingTalent.configEventListener(MouseEvent.CLICK, this.onMouseClick);
            this._btnFindingTalent.visible = false;
            this._fruits = UIFactory.gBitmap(ImagesConst.guidlRankFruite, 630, 0, this);
            this._fruits.visible = false;
            UIFactory.bg(0, 25, 690, 1, this, ImagesConst.SplitLine);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._isMyGuildEffect = null;
            this._isMyGuildEffect = null;
            this._txtRank = null;
            this._bmpRank = null;
            this._txtGuildName = null;
            this._txtGuildMaster = null;
            this._txtGuildPower = null;
            this._txtGuildLevel = null;
            this._txtGuildMembersNum = null;
            this._btnApplyGuild = null;
            this._btnEnterManor = null;
            this._btnFindingTalent = null;
            this._fruits = null;
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_3:Date = null;
            var _loc_4:Date = null;
            var _loc_5:Boolean = false;
            var _loc_2:* = param1 as SMiniGuildInfo;
            this._saveData = _loc_2;
            if (_loc_2.guildId == Cache.instance.guild.selfGuildInfo.guildID)
            {
                if (this._isMyGuildEffect == null)
                {
                    this._isMyGuildEffect = UIFactory.bg(0, 0, this.width, this.height, this, ImagesConst.selectedBg);
                }
                else
                {
                    this._isMyGuildEffect.visible = true;
                }
            }
            else if (this._isMyGuildEffect)
            {
                this._isMyGuildEffect.visible = false;
            }
            if (_loc_2.rank == 1)
            {
                this._bmpRank.bitmapData = GlobalClass.getBitmapData(ImagesConst.guildRank1_icon);
            }
            else if (_loc_2.rank == 2)
            {
                this._bmpRank.bitmapData = GlobalClass.getBitmapData(ImagesConst.guildRank2_icon);
            }
            else if (_loc_2.rank == 3)
            {
                this._bmpRank.bitmapData = GlobalClass.getBitmapData(ImagesConst.guildRank3_icon);
            }
            else
            {
                this._bmpRank.bitmapData = null;
            }
            this._txtRank.text = _loc_2.rank.toString();
            this._txtGuildName.htmlText = "<a href=\'event:guildlink\' target = \'\'><font color=\'#ffffff\'><u>" + _loc_2.guildName + "</u></font></a>";
            this._txtGuildName.configEventListener(TextEvent.LINK, this.onGuildLink);
            this._txtGuildMaster.text = _loc_2.leaderName;
            this._txtGuildPower.text = _loc_2.combat.toString();
            this._txtGuildLevel.text = _loc_2.level.toString();
            this._txtGuildMembersNum.text = _loc_2.playerNum + "/" + _loc_2.maxPlayerNum;
            if (GuildListPanel.PanelType == 0)
            {
                this._btnApplyGuild.visible = true;
                this._btnEnterManor.visible = false;
                this._btnFindingTalent.visible = false;
                this._btnApplyGuild.label = Cache.instance.guild.hasGuild ? ("" + Language.getString(71096)) : ("" + Language.getString(71097));
                if (Cache.instance.guild.selfGuildInfo.guildID != 0 && GuildConst.hasPermissions(GuildConst.FindingTalent))
                {
                    this._btnFindingTalent.visible = true;
                    this._btnApplyGuild.visible = false;
                    if (Cache.instance.guild.selfGuildInfo.guildID == _loc_2.guildId)
                    {
                        this._btnFindingTalent.visible = false;
                    }
                }
                if (Cache.instance.guild.hasGuild && Cache.instance.guild.selfGuildInfo.guildID == _loc_2.guildId)
                {
                    this._btnApplyGuild.visible = false;
                }
                if (_loc_2.playerNum >= _loc_2.maxPlayerNum)
                {
                    this._btnApplyGuild.enabled = false;
                    this._btnApplyGuild.filters = [FilterConst.colorFilter2];
                }
                else
                {
                    this._btnApplyGuild.enabled = true;
                    this._btnApplyGuild.filters = null;
                }
            }
            else if (GuildListPanel.PanelType == 1)
            {
                this._btnApplyGuild.visible = false;
                this._btnEnterManor.visible = true;
                this._btnFindingTalent.visible = false;
                _loc_3 = ClockManager.instance.nowDate;
                _loc_4 = this._saveData.nextPickUpDt;
                if (_loc_3.time >= _loc_4.time)
                {
                    this._fruits.visible = true;
                }
                else
                {
                    this._fruits.visible = false;
                }
            }
            if (this._btnApplyGuild.visible)
            {
                _loc_5 = ClientSetting.local.getIsDone(IsDoneType.HasGuideGuild);
                if (!_loc_5)
                {
                    this._btnApplyGuild.filters = [FilterConst.guideFilter];
                }
                else
                {
                    this._btnApplyGuild.filters = [];
                }
            }
            return;
        }// end function

        protected function onMouseClick(event:MouseEvent) : void
        {
            var obj:Object;
            var exitCallback:Function;
            var event:* = event;
            obj = new Object();
            obj.guildID = this._saveData.guildId;
            switch(event.target)
            {
                case this._btnApplyGuild:
                {
                    if (Cache.instance.guild.selfGuildInfo.baseInfo)
                    {
                        exitCallback = function (param1:int) : void
            {
                if (param1 == Alert.OK)
                {
                    obj.guildInfo = _saveData;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GUILD_APPLY, obj));
                }
                return;
            }// end function
            ;
                        Alert.show(Language.getStringByParam(71098, Cache.instance.guild.selfGuildInfo.baseInfo.guildName), null, Alert.OK | Alert.CANCEL, null, exitCallback);
                    }
                    else
                    {
                        obj.guildInfo = this._saveData;
                        Dispatcher.dispatchEvent(new DataEvent(EventName.GUILD_APPLY, obj));
                    }
                    break;
                }
                case this._btnEnterManor:
                {
                    if (Cache.instance.group.isInGroup)
                    {
                        MsgManager.showRollTipsMsg("" + Language.getString(71099));
                        return;
                    }
                    if (Cache.instance.guild.selfGuildInfo.selfInfo.level < 3)
                    {
                        MsgManager.showRollTipsMsg("" + Language.getString(71100));
                        return;
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.Guild_enterManor, this._saveData.guildId));
                    break;
                }
                case this._btnFindingTalent:
                {
                    GuildFindTalentPanel.instance.show();
                    GameProxy.guild.getOtherGuildMemberList(this._saveData.guildId);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        protected function onGuildLink(event:TextEvent) : void
        {
            GuildIntroducePanel.instance.setGuildInfo(this._saveData);
            GuildIntroducePanel.instance.show();
            return;
        }// end function

    }
}
